<template>
  <div class="NoticeDet">
    <!-- 页面主体信息区域 -->
    <div class="outermostMargin">
      <div class="msgBox">
        <div class="textBox">
          <div class="titles">
            <span class="mainTitle">{{detData.title}}</span>
            <p>
              <span class="time">{{detData.createTime}}</span>
              <span>{{detData.regionName}}</span>
            </p>
          </div>
        </div>
        <div class="imgBox" :style="'background-image: url('+picUrl(detData.url)+')'"></div>
        <div class="summary" style="overflow-x: hidden;width: 100%;" v-html="detData.description"></div>
        <div class="pl">
          <div class="divl" @click="comments('1')">
            <span class="btn">同意（{{values1}}）</span>
          </div>
          <div class="divl" @click="comments('2')">
            <span class="btn">反对（{{values2}}）</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    let date = this.slow.getTime("date");
    console.log(date);
    let localkey = date + "_zjl_" + this.$route.query.detData.id;
    let localValus = {
      zan: [],
      jiayou: [],
      leiren: []
    };
    if (window.localStorage.getItem(localkey)) {
      localValus = JSON.parse(window.localStorage.getItem(localkey));
    }
    return {
      det: {},
      detData: "",
      values1: "",
      values2: "",
      localkey: localkey,
      localValus: localValus
    };
  },
  created() {
    this.detData = JSON.parse(this.$route.query.detData);
    this.detData.description = this.replaceImgs(this.detData.description);
    this.detData.description = this.detData.description.replace(
      /\s(width:)/g,
      " width: 100%"
    );
    this.getsums();
  },
  methods: {
    getsums() {
      this.post("/procedure/get_vote", {
        relationId: this.detData.id
      }).then(r => {
        r.list.forEach(element => {
          if(element[0] == 1){
            this.values1 = element[1]
          }
          if(element[0] == 2){
            this.values2 = element[1]
          }
        });
      });
    },
    comments(type) {
      this.post("/procedure/addVote", {
        dataAreaCode: localStorage.getItem("dataAreaCode"),
        id: this.detData.id,
        userId: this.slow.userInfo
          ? this.slow.userInfo.openId
          : "8a4c60a170ec39780170f0759f720069",
        userName: this.slow.userInfo ? this.slow.userInfo.nickname : "测试",
        type: type
      }).then(r => {
        this.getsums();
        if (r.success) {
          this.$toast.success(r.message || "成功");
        } else {
          this.$toast(r.message || "失败");
        }
      });
    },
    back() {
      this.$router.isBack = true; // 将返回状态置为触发态，以边路由监听触发返回动画
      this.$router.back(); // 路由向后退一步
    },
    replaceImgs(htmlText) {
      return htmlText.replace(
        /\s(src=")/g,
        ' width="100%" height="150px" src="http://www.hkqwgb.cn:8080'
      );
      // replaceText = htmlText.replace(
      //   /\s(width:)/g,
      //   ' width: 100%'
      // );
      // this.detData.description = replaceText;
      // console.log("replaceText", replaceText);
    }
  }
};
</script>
<style lang="scss" scoped>
@import "~@/smobile.scss";
.NoticeDet {
  .header {
    padding: $sm-spaceing-block-sm 0 $sm-spaceing-block-sm 0;

    position: absolute;
    width: $sm-img-per-max;
    height: 21px;
    background: $sm-bg-color;
    z-index: 2;

    display: flex;
    flex-direction: row nowrap;
    justify-content: flex-start;
    .backIcon {
      position: absolute;
      white-space: nowrap;
      height: $sm-icon-px-md;
      z-index: 4;

      .iconImage {
        height: $sm-icon-px-md;
        width: $sm-icon-px-md;
        transform: rotateY(180deg);
      }
    }

    .theme {
      position: absolute;
      font-weight: bold;
      width: $sm-img-per-max;
      text-align: center;
      white-space: nowrap;
      z-index: 3;
    }
  }

  .outermostMargin {
    padding: $sm-spaceing-block-base;
    background: $sm-bg-color;
    color: $sm-text-color;
    font-size: $sm-font-size-lg;

    overflow: auto;
    height: 100vh;
    // margin: 41px 0 0 0;

    .msgBox {
      display: flex;
      flex-direction: column;
      justify-content: flex-start;

      .textBox {
        .titles {
          display: flex;
          flex-direction: column;
          margin: $sm-spacing-col-xl 0 0 0;

          .mainTitle {
            font-size: $sm-font-size-title;
            font-weight: bold;
            color: $sm-color-title;
          }
          p{
            span:nth-child(2){
              margin-left: 15px;
              background: #e5b03e;
              padding: 3px 6px;
              border-radius: 12px;
              color: #ffffff;
              font-size: $sm-font-size-sm;
            }
            .time {
              color: $sm-text-color-grey;
              font-size: $sm-font-size-sm;
              // margin-top: 5px;
            }
          }
          .time {
            padding: $sm-spacing-col-sm 0 $sm-spacing-col-sm 0;
            color: $sm-text-color-grey;
            font-size: $sm-font-size-lg;
          }
        }
      }
      .imgBox {
        width: $sm-img-per-max;
        height: $sm-img-size-maxp;
        background-repeat: no-repeat;
        background-size: 100% 100%;
      }
      .summary {
        // margin: $sm-spacing-col-lg 0 $sm-spacing-col-lg 0;
        color: $sm-color-title;
        span,
        p {
          width: 100% !important;
        }
      }
    }
  }
}
.pl {
  display: flex;
  text-align: center;
  line-height: 45px;
  font-size: 14px;
  .divl {
    flex: 1;
    color: #999;
    .btn {
      border: 1px solid #999;
      border-radius: 4px;
      padding: 5px;
      padding-left: 10px;
      padding-right: 10px;
    }
  }
}
</style>